home *** CD-ROM | disk | FTP | other *** search
/ Tears Of The Sun Press Kit / Tears of the Sun Press Kit.iso / pc / acrobat reader 5 pc / javascripts / aform.js
Text File  |  2002-12-13  |  35KB  |  1,247 lines

  1. /*
  2.     ==========================================================================
  3.     Module: AForm.js
  4.     ==========================================================================
  5.     Pre-canned functions to map the user interface into JavaScripts.
  6.     ==========================================================================
  7.     The Software, including this file, is subject to the End User License
  8.     Agreement.
  9.     Copyright (c) 1998, Adobe Systems Incorporated, All Rights Reserved.
  10.     ==========================================================================
  11. */
  12.  
  13. // The following code "exports" any strings in the list into the current scope.
  14. var esStrsToExport =["IDS_GREATER_THAN", "IDS_GT_AND_LT", "IDS_LESS_THAN", "IDS_INVALID_MONTH",
  15.                    "IDS_INVALID_DATE", "IDS_INVALID_VALUE", "IDS_AM", "IDS_PM", "IDS_MONTH_INFO", 
  16.                    "IDS_STARTUP_CONSOLE_MSG"];
  17.  
  18. for(var n = 0; n < esStrsToExport.length; n++)
  19.     eval(esStrsToExport[n] + " = " + app.getString("EScript", esStrsToExport[n]).toSource());
  20.  
  21. console.println(IDS_STARTUP_CONSOLE_MSG);
  22.  
  23. RE_NUMBER_ENTRY_DOT_SEP = new Array(
  24.     "[+-]?\\d*\\.?\\d*"
  25. );
  26. RE_NUMBER_COMMIT_DOT_SEP = new Array(
  27.     "[+-]?\\d+(\\.\\d+)?",        /* -1.0 or -1 */
  28.     "[+-]?\\.\\d+",                /* -.1 */
  29.     "[+-]?\\d+\\."                /* -1. */
  30. );
  31. RE_NUMBER_ENTRY_COMMA_SEP = new Array(
  32.     "[+-]?\\d*,?\\d*"
  33. );
  34. RE_NUMBER_COMMIT_COMMA_SEP = new Array(
  35.     "[+-]?\\d+([.,]\\d+)?",        /* -1,0 or -1 */
  36.     "[+-]?[.,]\\d+",                /* -,1 */
  37.     "[+-]?\\d+[.,]"                /* -1, */
  38. );
  39. RE_ZIP_ENTRY = new Array(
  40.     "\\d{0,5}"
  41. );
  42. RE_ZIP_COMMIT = new Array(
  43.     "\\d{5}"
  44. );
  45. RE_ZIP4_ENTRY = new Array(
  46.     "\\d{0,5}(\\.|[- ])?\\d{0,4}"
  47. );
  48. RE_ZIP4_COMMIT = new Array(
  49.     "\\d{5}(\\.|[- ])?\\d{4}"
  50. );
  51. RE_PHONE_ENTRY = new Array(
  52.     "\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",        /* 555-1234 or 408 555-1234 */
  53.     "\\(\\d{0,3}",                                            /* (408 */
  54.     "\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",    /* (408) 555-1234 */
  55.         /* (allow the addition of parens as an afterthought) */
  56.     "\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",    /* (408 555-1234 */
  57.     "\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",    /* 408) 555-1234 */
  58.     "011(\\.|[- \\d])*"                                        /* international */
  59. );
  60. RE_PHONE_COMMIT = new Array(
  61.     "\\d{3}(\\.|[- ])?\\d{4}",                            /* 555-1234 */
  62.     "\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}",            /* 408 555-1234 */
  63.     "\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}",    /* (408) 555-1234 */
  64.     "011(\\.|[- \\d])*"                                    /* international */
  65. );
  66. RE_SSN_ENTRY = new Array(
  67.     "\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"
  68. );
  69. RE_SSN_COMMIT = new Array(
  70.     "\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"
  71. );
  72.  
  73. /* Function definitions for the color object. */
  74.  
  75. function ColorConvert(oColor, cColorspace)
  76. {    // Converts a color to a specific colorspace.
  77.     var oOut = oColor;
  78.  
  79.     switch (cColorspace) {
  80.         case "G":
  81.             // Note that conversion to the DeviceGray colorspace is lossy in the same
  82.             // way that a color signal on a B/W TV is lossy.
  83.             if (oColor[0] == "RGB")
  84.                 oOut = new Array("G", 0.3 * oColor[1] + 0.59 * oColor[2] + 0.11 * oColor[3]);
  85.             else if (oColor[0] == "CMYK")
  86.                 oOut = new Array("G", 1.0 - Math.min(1.0, 
  87.                     0.3 * oColor[1] + 0.59 * oColor[2] + 0.11 * oColor[3] + oColor[4]));
  88.         break;
  89.         case "RGB":
  90.             if (oColor[0] == "G")
  91.                 oOut = new Array("RGB", oColor[1], oColor[1], oColor[1]);
  92.             else if (oColor[0] == "CMYK")
  93.                 oOut = new Array("RGB", 1.0 - Math.min(1.0, oColor[1] + oColor[4]), 
  94.                     1.0 - Math.min(1.0, oColor[2] + oColor[4]),
  95.                     1.0 - Math.min(1.0, oColor[3] + oColor[4]));
  96.         break;
  97.         case "CMYK":
  98.             if (oColor[0] == "G")
  99.                 oOut = new Array("CMYK", 0, 0, 0, 1.0 - oColor[1]);
  100.             else if (oColor[0] == "RGB")
  101.                 oOut = new Array("CMYK", 1.0 - oColor[1], 1.0 - oColor[2], 1.0 - oColor[3], 0); 
  102.         break;
  103.     }
  104.  
  105.     return oOut;
  106. }
  107.  
  108. function ColorEqual(c1, c2)
  109. {    // Compare two colors. 
  110.     /* The gray colorspace conversion is lossy so we avoid if possible. */
  111.     if (c1[0] == "G")
  112.         c1 = color.convert(c1, c2[0]);
  113.     else
  114.         c2 = color.convert(c2, c1[0]);
  115.  
  116.     /* Colorspace must be equal. */
  117.     if (c1[0] != c2[0])    {
  118.         return false;
  119.     }
  120.  
  121.     /* Compare the individual components. */
  122.     var nComponents = 0;
  123.         
  124.     switch (c1[0]) {
  125.         case "G":
  126.             nComponents = 1;
  127.         break;
  128.         case "RGB":
  129.             nComponents = 3;
  130.         break;
  131.         case "CMYK":
  132.             nComponents = 4;
  133.         break;
  134.     }
  135.  
  136.     for (var i = 1; i <= nComponents; i++) {
  137.         if (c1[i] != c2[i])    {
  138.             return false;
  139.         }
  140.     }
  141.  
  142.     return true;
  143. }
  144.  
  145. /* ==== Convenience Objects ==== */
  146.  
  147. /* Stock color definitions for ease of use. */
  148. color = new Object();
  149. color.equal = ColorEqual;
  150. color.convert = ColorConvert;
  151. color.transparent = new Array("T");
  152. color.black = new Array("G", 0);
  153. color.white = new Array("G", 1);
  154. color.dkGray = new Array("G", 0.25);
  155. color.gray = new Array("G", 0.5);
  156. color.ltGray = new Array("G", 0.75);
  157. color.red = new Array("RGB", 1, 0, 0);
  158. color.green = new Array("RGB", 0, 1, 0);
  159. color.blue = new Array("RGB", 0, 0, 1);
  160. color.cyan = new Array("CMYK", 1, 0, 0, 0);
  161. color.magenta = new Array("CMYK", 0, 1, 0, 0);
  162. color.yellow = new Array("CMYK", 0, 0, 1, 0);
  163.  
  164. /* Font definitions for ease of use */
  165. font = new Object();
  166. font.Times = "Times-Roman";
  167. font.TimesB = "Times-Bold";
  168. font.TimesI = "Times-Italic";
  169. font.TimesBI = "Times-BoldItalic";
  170. font.Helv = "Helvetica";
  171. font.HelvB = "Helvetica-Bold";
  172. font.HelvI = "Helvetica-Oblique";
  173. font.HelvBI = "Helvetica-BoldOblique";
  174. font.Cour = "Courier";
  175. font.CourB = "Courier-Bold";
  176. font.CourI = "Courier-Oblique";
  177. font.CourBI = "Courier-BoldOblique";
  178. font.Symbol = "Symbol";
  179. font.ZapfD = "ZapfDingbats";
  180. font.KaGo = "HeiseiKakuGo-W5-UniJIS-UCS2-H";
  181. font.KaMi = "HeiseiMin-W3-UniJIS-UCS2-H";
  182.  
  183. /* Border style definitions for ease of use */
  184. border = new Object();
  185. border.s = "solid";
  186. border.d = "dashed";
  187. border.b = "beveled";
  188. border.i = "inset";
  189. border.u = "underline";
  190.  
  191. /* Radio/Check button style definitions for ease of use */
  192. style = new Object();
  193. style.ch = "check";
  194. style.cr = "cross";
  195. style.di = "diamond";
  196. style.ci = "circle";
  197. style.st = "star";
  198. style.sq = "square"; 
  199.  
  200. /* highlight modes of on a push button */
  201. highlight = new Object();
  202. highlight.n = "none";
  203. highlight.i = "invert";
  204. highlight.p = "push";
  205. highlight.o = "outline";
  206.  
  207. /* zoom types for a document */
  208. zoomtype = new Object();
  209. zoomtype.none = "NoVary";
  210. zoomtype.fitW = "FitWidth";
  211. zoomtype.fitH = "FitHeight";
  212. zoomtype.fitP = "FitPage";
  213. zoomtype.fitV = "FitVisibleWidth";
  214. zoomtype.pref = "Preferred";
  215.  
  216. /* Cursor behavior in full screen mode. */
  217. cursor = new Object();
  218. cursor.visible = 0;
  219. cursor.hidden = 1;
  220. cursor.delay = 2;
  221.  
  222. /* Transition definitions. */
  223. trans = new Object();
  224. trans.blindsH        = "BlindsHorizontal";
  225. trans.blindsV        = "BlindsVertical";
  226. trans.boxI            = "BoxIn";
  227. trans.boxO            = "BoxOut";
  228. trans.dissolve        = "Dissolve";
  229. trans.glitterD        = "GlitterDown";
  230. trans.glitterR        = "GlitterRight";
  231. trans.glitterRD        = "GlitterRightDown";
  232. trans.random        = "Random";
  233. trans.replace        = "Replace";
  234. trans.splitHI        = "SplitHorizontalIn";
  235. trans.splitHO        = "SplitHorizontalOut";
  236. trans.splitVI        = "SplitVerticalIn";
  237. trans.splitVO        = "SplitVerticalOut";
  238. trans.wipeD            = "WipeDown";
  239. trans.wipeL            = "WipeLeft";
  240. trans.wipeR            = "WipeRight";
  241. trans.wipeU            = "WipeUp";
  242.  
  243. /* Icon/Text placement. */
  244. position = new Object();
  245. position.textOnly    = 0;
  246. position.iconOnly    = 1;
  247. position.iconTextV    = 2;
  248. position.textIconV    = 3;
  249. position.iconTextH    = 4;
  250. position.textIconH    = 5;
  251. position.overlay    = 6;
  252.  
  253. /* When does icon scale. */
  254. scaleWhen = new Object();
  255. scaleWhen.always    = 0;
  256. scaleWhen.never        = 1;
  257. scaleWhen.tooBig    = 2;
  258. scaleWhen.tooSmall    = 3;
  259.  
  260. /* How does icon scale. */
  261. scaleHow = new Object();
  262. scaleHow.proportional    = 0;
  263. scaleHow.anamorphic        = 1;
  264.  
  265.  
  266. /* Field display. */
  267. display = new Object();
  268. display.visible        = 0;
  269. display.hidden        = 1;
  270. display.noPrint        = 2;
  271. display.noView        = 3;
  272.  
  273. /* ==== Functions ==== */
  274.  
  275. /* these may be used a lot -- they are language independent */
  276.  
  277. AFDigitsRegExp = new RegExp();
  278. AFDigitsRegExp.compile("\\d+");
  279. AFPMRegExp = new RegExp();
  280. AFPMRegExp.compile(IDS_PM, "i");
  281. AFAMRegExp = new RegExp();
  282. AFAMRegExp.compile(IDS_AM, "i");
  283. AFTimeLongRegExp = new RegExp();
  284. AFTimeLongRegExp.compile("\\d{1,2}:\\d{1,2}:\\d{1,2}");
  285. AFTimeShortRegExp = new RegExp();
  286. AFTimeShortRegExp.compile("\\d{1,2}:\\d{1,2}");
  287.  
  288. function AFBuildRegExps(array)
  289. /* Takes an array of strings and turns it into an array of compiled regular
  290.  * expressions -- is used for the definitions that follow */
  291. {
  292.     var retVal = new Array();
  293.  
  294.     retVal.length = array.length;
  295.     for(var it = 0; it < array.length; it++)
  296.     {
  297.         retVal[it] = new RegExp();
  298.         retVal[it].compile(array[it], "i");
  299.     }
  300.     return retVal;
  301. }
  302.  
  303. /* these may be used a lot -- they are NOT language independent and are 
  304.  * derived from the localizable (RE_xxx) stuff above */
  305.  
  306. AFNumberDotSepEntryRegExp = AFBuildRegExps(RE_NUMBER_ENTRY_DOT_SEP);
  307. AFNumberDotSepCommitRegExp = AFBuildRegExps(RE_NUMBER_COMMIT_DOT_SEP);
  308. AFNumberCommaSepEntryRegExp = AFBuildRegExps(RE_NUMBER_ENTRY_COMMA_SEP);
  309. AFNumberCommaSepCommitRegExp = AFBuildRegExps(RE_NUMBER_COMMIT_COMMA_SEP);
  310. AFZipEntryRegExp = AFBuildRegExps(RE_ZIP_ENTRY);
  311. AFZipCommitRegExp = AFBuildRegExps(RE_ZIP_COMMIT);
  312. AFZip4EntryRegExp = AFBuildRegExps(RE_ZIP4_ENTRY);
  313. AFZip4CommitRegExp = AFBuildRegExps(RE_ZIP4_COMMIT);
  314. AFPhoneEntryRegExp = AFBuildRegExps(RE_PHONE_ENTRY);
  315. AFPhoneCommitRegExp = AFBuildRegExps(RE_PHONE_COMMIT);
  316. AFSSNEntryRegExp = AFBuildRegExps(RE_SSN_ENTRY);
  317. AFSSNCommitRegExp = AFBuildRegExps(RE_SSN_COMMIT);
  318. AFMonthsRegExp = AFBuildRegExps(IDS_MONTH_INFO.split(/\[\d+\]/));
  319.  
  320. function AFExactMatch(rePatterns, sString)
  321. {    /* match a string against an array of RegExps */
  322.     var it;
  323.  
  324.     if(!rePatterns.length && rePatterns.test(sString) && RegExp.lastMatch == sString)
  325.         return true;
  326.     for(it = 0; it < rePatterns.length; it++)
  327.         if(rePatterns[it].test(sString) && RegExp.lastMatch == sString)
  328.             return it + 1;
  329.     return 0;
  330. }
  331.  
  332. function AFExtractNums(string)
  333. {    /* returns an array of numbers that it managed to extract from the given 
  334.      * string or null on failure */
  335.     var nums = new Array();
  336.  
  337.     if (string.charAt(0) == '.' || string.charAt(0) == ',')
  338.         string = "0" + string;
  339.          
  340.     while(AFDigitsRegExp.test(string)) {
  341.         nums.length++;
  342.         nums[nums.length - 1] = RegExp.lastMatch;
  343.         string = RegExp.rightContext;
  344.     }
  345.     if(nums.length >= 1) return nums;
  346.     return null;
  347. }
  348.  
  349. function AFMakeNumber(string)
  350. {    /* attempts to make a number out of a string that may not use '.' as the
  351.      * seperator; it expects that the number is fairly well-behaved other than
  352.      * possibly having a non-JavaScript friendly separator */
  353.     var type = typeof string;
  354.  
  355.     if (type == "number")
  356.         return string;
  357.     if (type != "string")
  358.         return null;
  359.  
  360.     var array = AFExtractNums(string);
  361.  
  362.     if(array)
  363.     {
  364.         var joined = array.join(".");
  365.  
  366.         if (string.indexOf("-.") >= 0)
  367.             joined = "0." + joined;
  368.         return joined * (string.indexOf("-") >= 0 ? -1.0 : 1.0);
  369.     }
  370.     else
  371.         return null;
  372. }
  373.  
  374. function AFExtractRegExp(rePattern, string)
  375. {    /* attempts to match the pattern given against the string given; on 
  376.      * success, returns an array containing (at index 0) the initial
  377.      * string with the matched text removed and (at index 1) the matched
  378.      * text; on failure, returns null */
  379.     var retVal = new Array();
  380.  
  381.     if(rePattern.test(string))
  382.     {
  383.         retVal.length = 2;
  384.         retVal[0] = RegExp.leftContext + RegExp.rightContext;
  385.         retVal[1] = RegExp.lastMatch;
  386.         return retVal;
  387.     }
  388.     return null;
  389. }
  390.  
  391. function AFMakeArrayFromList(string)
  392. {
  393.   var type = typeof string;
  394.  
  395.   if(type == "string")
  396.   {
  397.      var reSep = new RegExp();
  398.     reSep.compile(",[ ]?");
  399.     return string.split(reSep);
  400.   }
  401.   return string;
  402. }
  403.  
  404. function AFExtractTime(string)
  405. {    /* attempts to extract a WELL FORMED time from a string; returned 
  406.      * is an array in the same vein as AFExtractRegExp or null on
  407.      * failure. a WELL FORMED time looks like 12:23:56pm */
  408.     
  409.     var pm = "";
  410.     var info;
  411.  
  412.     info = AFExtractRegExp(AFPMRegExp, string);
  413.     if(info)
  414.     {
  415.         pm = info[1];
  416.         string = info[0];
  417.     }
  418.     info = AFExtractRegExp(AFAMRegExp, string);
  419.     if(info)
  420.     {
  421.         string = info[0];
  422.     }
  423.     info = AFExtractRegExp(AFTimeLongRegExp, string);
  424.     if(info)
  425.     {
  426.         info[1] += pm;
  427.         return info;
  428.     }
  429.     info = AFExtractRegExp(AFTimeShortRegExp, string);
  430.     if(info)
  431.     {
  432.         info[1] += pm;
  433.         return info;
  434.     }
  435.  
  436.     return null;
  437. }
  438.  
  439. function AFGetMonthIndex(string)
  440. {    /* attempts to identify the given string as a month or a valid abbreviation,
  441.      * it expects the given string to be the valid month from the matced RegExp.
  442.      * returns the month index (January = 1) or zero on failure */
  443.     var monthre = new RegExp(string + "\\[(\\d+)\\]", "i");
  444.     var result = monthre.exec(IDS_MONTH_INFO);
  445.     
  446.     if(string && result) return 1.0 * result[1];
  447.     return 0;
  448. }
  449.  
  450. function AFMatchMonth(string)
  451. {    /* attempts to find a valid month embedded in a string; returns the month
  452.      * index (January = 1) or zero on failure */
  453.  
  454.     for(var it = 0; it < AFMonthsRegExp.length; it++)
  455.         if(AFMonthsRegExp[it].test(string))
  456.             return AFGetMonthIndex(RegExp.lastMatch);
  457.     return 0;
  458. }
  459.  
  460. function AFGetMonthString(index)
  461. {    /* returns the string corresponding to the given month or a string that
  462.      * is indicative of the fact that the index was invalid */
  463.     var monthre = new RegExp("(\\w+)\\[" + index + "\\]");
  464.     var result = monthre.exec(IDS_MONTH_INFO);
  465.  
  466.     if(result) return result[1];
  467.     return IDS_INVALID_MONTH;
  468. }
  469.  
  470. function AFParseTime(string, date)
  471. {    /* attempts to parse a string containing a time; returns null on failure
  472.      * or a Date object on success. Time can be in ugly format. */
  473.     var pm, am;
  474.     var nums = AFExtractNums(string);
  475.     if (!date)
  476.         date = new Date();
  477.     var hour, minutes, seconds;
  478.  
  479.     if(!string) return date;
  480.     if(!nums) return null;
  481.     if(nums.length < 2 || nums.length > 3) return null;
  482.     if(AFPMRegExp.test(string)) pm = true;
  483.     else pm = false;
  484.     if(AFAMRegExp.test(string)) am = true;
  485.     else am = false;
  486.     hour = new Number(nums[0]); /* force it to number */
  487.     if(pm)
  488.     {
  489.         if(hour < 12) hour += 12;
  490.     }
  491.     else if (am)
  492.     {
  493.         if(hour >= 12) hour -= 12;
  494.     }
  495.     minutes = nums[1];
  496.     if(nums.length == 3) seconds = nums[2];
  497.     else seconds = 0;
  498.     date.setHours(hour);
  499.     date.setMinutes(minutes);
  500.     date.setSeconds(seconds);
  501.     if(date.getHours() != hour)
  502.         return null;
  503.     if(date.getMinutes() != minutes)
  504.         return null;
  505.     if(date.getSeconds() != seconds)
  506.         return null;
  507.     return date;
  508. }
  509.  
  510. function AFDateFromYMD(nYear, nMonth, nDate)
  511. {    /* Validates the given fields and returns a date based on them */
  512.     var dDate = new Date();
  513.  
  514.     dDate.setFullYear(nYear, nMonth, nDate);
  515.     if(dDate.getFullYear() != nYear)
  516.         return null;
  517.     if(dDate.getMonth() != nMonth)
  518.         return null;
  519.     if(dDate.getDate() != nDate)
  520.         return null;
  521.     return dDate;
  522. }
  523.  
  524. function AFParseDateEx(cString, cOrder)
  525. {    /* Attempts to parse a string containing some form of date; returns null
  526.     ** on failure or a Date object on success. cOrder should be the order in
  527.     ** which the date is entered (e.g. ymd, mdy, etc.). Use AFParseDateOrder to
  528.     ** generate this string from an arbitrary format string. */
  529.     var nYear;
  530.     var nMonth;
  531.     var nDate;
  532.     var nYCount;
  533.     var dDate = new Date();
  534.  
  535.     dDate.setHours(12, 0, 0);
  536.  
  537.     /* Empty string returns current date/time. */
  538.     if (!cString) { 
  539.         return dDate;
  540.     }
  541.  
  542.     nYCount = AFParseDateYCount(cOrder); /* count the number of digits for year in the selected format */
  543.     cOrder = AFParseDateOrder(cOrder); /* make sure its in the "ymd" format */
  544.  
  545.     /* Extract any time information in the string. */
  546.     var info = AFExtractTime(cString);
  547.     if (info)
  548.         cString = info[0];
  549.  
  550.     /* Break down the date into an array of numbers. */
  551.     var aNums = AFExtractNums(cString);
  552.     if(!aNums) 
  553.         return null;    /* No numbers? */
  554.  
  555.     /* User supplied three numbers. */
  556.     if (aNums.length == 3) {
  557.         nYear = 1.0 * aNums[cOrder.indexOf("y")];
  558.         if (nYCount > 2 && nYear < 100)
  559.             return null; /* must enter 4 digits for the year to match with the format of the field */
  560.         nYear = AFDateHorizon(nYear);
  561.  
  562.         dDate = AFDateFromYMD(nYear, aNums[cOrder.indexOf("m")] - 1, aNums[cOrder.indexOf("d")]);
  563.         if (info)
  564.             dDate = AFParseTime(info[1], dDate);
  565.         return dDate;
  566.     }
  567.  
  568.     /* Find text based month, if supplied. */
  569.     nMonth = AFMatchMonth(cString);    
  570.  
  571.     /* User supplied two numbers. */
  572.     if(aNums.length == 2) {
  573.         if (nMonth) {
  574.             /* Easy case, the month was text and we have two numbers. */
  575.             if (cOrder.indexOf("y") < cOrder.indexOf("d")) {
  576.                 nYear = 1.0 * aNums[0];
  577.                 nDate = aNums[1];
  578.             } else {
  579.                 nYear = 1.0 * aNums[1];
  580.                 nDate = aNums[0];
  581.             }
  582.             if (nYCount > 2 && nYear < 100)
  583.                 return null; /* must enter 4 digits for the year to match with the format of the field */
  584.         
  585.             nYear = AFDateHorizon(nYear);
  586.             dDate = AFDateFromYMD(nYear, nMonth - 1, nDate);
  587.  
  588.             if (info)
  589.                 dDate = AFParseTime(info[1], dDate);
  590.             return dDate;
  591.         }
  592.  
  593.         /* More difficult case. We have two numbers and three slots, how
  594.         ** to allocate them? */
  595.         if (cOrder.indexOf("y") < cOrder.indexOf("d"))    {
  596.             /* Year comes before date and as such we allocate the two
  597.             ** numbers to the month and the year only. */
  598.             if (cOrder.indexOf("y") < cOrder.indexOf("m")) {
  599.                 nYear = 1.0 * aNums[0];
  600.                 nMonth = aNums[1];
  601.             } else {
  602.                 nYear = 1.0 * aNums[1];
  603.                 nMonth = aNums[0];
  604.             }
  605.             if (nYCount > 2 && nYear < 100)
  606.                 return null; /* must enter 4 digits for the year to match with the format of the field */
  607.         
  608.             nYear = AFDateHorizon(nYear);
  609.             dDate = AFDateFromYMD(nYear, nMonth - 1, 1);
  610.         } else {
  611.             /* Date comes before year and so we allocate the two numbers
  612.             ** to the date and the month only. */
  613.             nYear = dDate.getFullYear();
  614.             if (cOrder.indexOf("d") < cOrder.indexOf("m")) {
  615.                 dDate = AFDateFromYMD(nYear, aNums[1] - 1, aNums[0]);
  616.             } else {
  617.                 dDate = AFDateFromYMD(nYear, aNums[0] - 1, aNums[1]);
  618.             }
  619.         }
  620.     
  621.         if (info)
  622.             dDate = AFParseTime(info[1], dDate);
  623.         return dDate;
  624.     }
  625.  
  626.     /* User supplied one number. */
  627.     if(aNums.length == 1)    {
  628.         if (nMonth) {
  629.             /* We have one number and two slots (y/d) and need to allocate
  630.             ** them based on who came first in the format. */
  631.             if(cOrder.indexOf("y") < cOrder.indexOf("d")) {
  632.                 nYear = 1.0 * aNums[0];
  633.                 if (nYCount > 2 && nYear < 100)
  634.                     return null; /* must enter 4 digits for the year to match with the format of the field */
  635.             
  636.                 nYear = AFDateHorizon(nYear);
  637.                 dDate = AFDateFromYMD(nYear, nMonth - 1, 1);
  638.             } else {
  639.                 nYear = dDate.getFullYear();
  640.                 dDate = AFDateFromYMD(nYear, nMonth - 1, aNums[0]);
  641.             }
  642.             if (info)
  643.                 dDate = AFParseTime(info[1], date);
  644.             return dDate;
  645.         }
  646.  
  647.         /* We have one number and three slots and need to allocate them
  648.         ** based on who came first in the format. */
  649.         nYear = dDate.getFullYear();
  650.         nMonth = dDate.getMonth();
  651.         nDate = dDate.getDate();
  652.         switch (cOrder.charAt(0)) {
  653.             case "y":
  654.                 nYear = 1.0 * aNums[0];
  655.                 if (nYCount > 2 && nYear < 100)
  656.                     return null; /* must enter 4 digits for the year to match with the format of the field */
  657.             
  658.                 nYear = AFDateHorizon(nYear);
  659.             break;
  660.             case "m":
  661.                 nMonth = aNums[0] - 1;
  662.             break;
  663.             case "d":
  664.                 nDate = aNums[0];
  665.             break;
  666.         }
  667.         dDate = AFDateFromYMD(nYear, nMonth, nDate);
  668.  
  669.  
  670.         if (info)
  671.             dDate = AFParseTime(info[1], date);
  672.         return dDate;
  673.     }
  674.  
  675.     /* No idea how to deal with the other combinations. */
  676.     return null;
  677. }
  678.  
  679. function AFDateHorizon(nYear)
  680. {    /* Takes the year supplied and applies the date horizon heuristic.
  681.     ** All years between 50 and 100 we add 1900. All years less than 50 we add 2000. */
  682.     if (nYear < 100 && nYear >= 50) {
  683.         nYear += 1900;
  684.     } else if (nYear >= 0 && nYear < 50) {
  685.         nYear += 2000;
  686.     }
  687.  
  688.     return nYear;
  689. }
  690.  
  691. function AFParseDate(string, longEntry, shortEntry, wordMonthEntry, monthYearEntry)
  692. {    /* OBSOLETE: Use AFParseDateEx instead. */
  693.     var nums;
  694.     var year, month;
  695.     var date;
  696.     var info = AFExtractTime(string);
  697.  
  698.     if(!string) return new Date();
  699.  
  700.     if(info)
  701.         string = info[0];
  702.  
  703.     date = new Date();
  704.     nums = AFExtractNums(string);
  705.     if(!nums) return null;
  706.     if(nums.length == 3)
  707.     {
  708.         year = 1.0 * nums[eval(longEntry.charAt(0))];
  709.         year = AFDateHorizon(year);
  710.         date = AFDateFromYMD(year, nums[eval(longEntry.charAt(1))] - 1, nums[eval(longEntry.charAt(2))]);
  711.         if (info)
  712.             date = AFParseTime(info[1], date);
  713.         return date;
  714.     }
  715.     month = AFMatchMonth(string);
  716.     if(nums.length == 2)
  717.     {
  718.         if(month)
  719.         {
  720.             year = 1.0 * nums[eval(wordMonthEntry.charAt(0))];
  721.             year = AFDateHorizon(year);
  722.             date = AFDateFromYMD(year, month - 1, nums[eval(wordMonthEntry.charAt(1))]);
  723.             if (info)
  724.                 date = AFParseTime(info[1], date);
  725.             return date;
  726.         }
  727.         if(monthYearEntry)
  728.         {
  729.             year = 1.0 * nums[eval(monthYearEntry.charAt(0))];
  730.             year = AFDateHorizon(year);
  731.             date = AFDateFromYMD(year, nums[eval(monthYearEntry.charAt(1))] - 1, 1);
  732.         }
  733.         else
  734.             date = AFDateFromYMD(date.getFullYear(),
  735.                 nums[eval(shortEntry.charAt(0))] - 1,
  736.                 nums[eval(shortEntry.charAt(1))]);
  737.         if (info)
  738.             date = AFParseTime(info[1], date);
  739.         return date;
  740.     }
  741.     if(month && nums.length == 1)
  742.     {
  743.         if(monthYearEntry)
  744.         {
  745.             year = 1.0 * nums[0];
  746.             year = AFDateHorizon(year);
  747.             date = AFDateFromYMD(year, month - 1, 1);
  748.         }
  749.         else
  750.             date = AFDateFromYMD(date.getFullYear(), month - 1,    nums[0]);
  751.         if (info)
  752.             date = AFParseTime(info[1], date);
  753.         return date;
  754.     }
  755.  
  756.     return null;
  757. }
  758.  
  759. function AFParseDateWithPDF(value, pdf)
  760. { /* OBSOLETE: Use AFParseDateEx instead. */
  761.     var cOldFormats = new Array(
  762.         "m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
  763.         "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
  764.         "m/d/yy h:MM tt", "m/d/yy HH:MM" );
  765.    
  766.     return AFParseDateEx(value, cOldFormats[pdf]);
  767. }
  768.  
  769. function AFMergeChange(event)
  770. {    /* merges the last change with the uncommitted change */
  771.     var prefix, postfix;
  772.     var value = event.value;
  773.  
  774.     if(event.willCommit) return event.value;
  775.     if(event.selStart >= 0)
  776.         prefix = value.substring(0, event.selStart);
  777.     else prefix = "";
  778.     if(event.selEnd >= 0 && event.selEnd <= value.length)
  779.         postfix = value.substring(event.selEnd, value.length);
  780.     else postfix = "";
  781.     return prefix + event.change + postfix;
  782. }
  783.  
  784. function AFRange_Validate(bGreaterThan, nGreaterThan, bLessThan, nLessThan)
  785. {       /* This function validates the current event to ensure that its value is 
  786.     ** within the specified range. */
  787.     var cError = "";
  788.  
  789.     if (event.value == "")
  790.         return;
  791.  
  792.     if (bGreaterThan && bLessThan) {
  793.         if (event.value < nGreaterThan || event.value > nLessThan)
  794.             cError = util.printf(IDS_GT_AND_LT, nGreaterThan, nLessThan);
  795.     } else if (bGreaterThan) {
  796.         if (event.value < nGreaterThan)
  797.             cError = util.printf(IDS_GREATER_THAN, nGreaterThan);
  798.     } else if (bLessThan) {
  799.         if (event.value > nLessThan)
  800.             cError = util.printf(IDS_LESS_THAN, nLessThan);
  801.     }
  802.     
  803.     if (cError != "") {
  804.         app.alert(cError, 0);
  805.         event.rc = false;
  806.     }
  807. }
  808.  
  809. function AFSimpleInit(cFunction)
  810. {    /* Convenience function used by AFSimple_Calculate. */
  811.     switch (cFunction)
  812.     {
  813.         case "PRD":
  814.             return 1.0;
  815.             break;
  816.     }
  817.  
  818.     return 0.0;
  819. }
  820.  
  821. function AFSimple(cFunction, nValue1, nValue2)
  822. {    /* Convenience function used by AFSimple_Calculate. */
  823.     var nValue = 1.0 * nValue1;
  824.  
  825.     /* Have to do this otherwise JavaScript thinks it's dealing with strings. */
  826.     nValue1 = 1.0 * nValue1;
  827.     nValue2 = 1.0 * nValue2;
  828.  
  829.     switch (cFunction)
  830.     {
  831.         case "AVG":
  832.         case "SUM":
  833.             nValue = nValue1 + nValue2;
  834.             break;
  835.         case "PRD":
  836.             nValue = nValue1 * nValue2;
  837.             break;
  838.         case "MIN":
  839.             nValue = Math.min(nValue1,nValue2);
  840.             break;
  841.         case "MAX":
  842.             nValue = Math.max(nValue1, nValue2);
  843.             break;
  844.     }
  845.  
  846.     return nValue;
  847. }
  848.  
  849. function AFSimple_Calculate(cFunction, cFields)
  850. {   /* Calculates the sum, average, product, etc. of the listed field values. */
  851.     var nFields = 0;
  852.     var nValue = AFSimpleInit(cFunction);
  853.  
  854.     /* Field name separator is one or more spaces followed by a comma, 
  855.     ** followed by one or more spaces.
  856.     ** or an array of field names */
  857.      var aFields = AFMakeArrayFromList(cFields);
  858.  
  859.     for (var i = 0; i < aFields.length; i++) {
  860.         /* Found a field, process it's value. */
  861.         var f = this.getField(aFields[i]);
  862.         var a = f.getArray();
  863.  
  864.         for (var j = 0; j < a.length; j++) {
  865.             var nTemp = AFMakeNumber(a[j].value); 
  866.             if (i == 0 && j == 0 && (cFunction == "MIN" || cFunction == "MAX"))
  867.                 nValue = nTemp;
  868.             nValue = AFSimple(cFunction, nValue, nTemp);
  869.             nFields++;
  870.         }
  871.     }
  872.  
  873.     if (cFunction == "AVG" && nFields > 0)
  874.         nValue /= nFields;
  875.  
  876.     event.value = nValue;
  877. }
  878.  
  879. function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
  880. {       /* This function validates the current keystroke event to make sure the
  881.         key pressed is reasonable for a numeric field. */
  882.  
  883.     var value = AFMergeChange(event);
  884.     var commit, noCommit;
  885.  
  886.     if(!value) return;
  887.     if(sepStyle > 1)
  888.     {
  889.         commit = AFNumberCommaSepCommitRegExp;
  890.         noCommit = AFNumberCommaSepEntryRegExp;
  891.     }
  892.     else
  893.     {
  894.         commit = AFNumberDotSepCommitRegExp;
  895.         noCommit = AFNumberDotSepEntryRegExp;
  896.     }
  897.     if(!AFExactMatch(event.willCommit ? commit : noCommit, value))
  898.     {
  899.         if (event.willCommit) {
  900.             var cAlert = IDS_INVALID_VALUE;
  901.             if (event.target != null)
  902.                 cAlert += " [ " + event.target.name + " ]";
  903.             app.alert(cAlert);
  904.         }
  905.         else
  906.             app.beep(0);
  907.         event.rc = false;
  908.     }
  909. }
  910.  
  911. function AFPercent_Keystroke(nDec, sepStyle)
  912. {
  913.         AFNumber_Keystroke(nDec, sepStyle, 0, 0, "", true);
  914. }
  915.  
  916. function AFSpecial_Keystroke(psf)
  917. {       /* This function validates the current keystroke event to make sure the
  918.         key pressed is reasonable for a "special" field. */
  919.         
  920.     /* The special formats, indicated by psf, are:
  921.     
  922.     psf             format
  923.     ---             ------
  924.     0               zip code
  925.     1               zip + 4
  926.     2               phone
  927.     3                SSN
  928.     
  929.     */
  930.  
  931.     var value = AFMergeChange(event);
  932.     var commit, noCommit;
  933.  
  934.     if(!value) return;
  935.     switch (psf)
  936.     {
  937.         case 0:
  938.             commit = AFZipCommitRegExp;
  939.             noCommit = AFZipEntryRegExp;
  940.             break;
  941.         case 1:
  942.             commit = AFZip4CommitRegExp;
  943.             noCommit = AFZip4EntryRegExp;
  944.             break;
  945.         case 2:
  946.             commit = AFPhoneCommitRegExp;
  947.             noCommit = AFPhoneEntryRegExp;
  948.             break;
  949.         case 3:
  950.             commit = AFSSNCommitRegExp;
  951.             noCommit = AFSSNEntryRegExp;
  952.             break;
  953.     }        
  954.     if(!AFExactMatch(event.willCommit ? commit : noCommit, value))
  955.     {
  956.         if (event.willCommit) {
  957.             var cAlert = IDS_INVALID_VALUE;
  958.             if (event.target != null)
  959.                 cAlert += " [ " + event.target.name + " ]";
  960.             app.alert(cAlert);
  961.         }
  962.         else
  963.             app.beep(0);
  964.         event.rc = false;
  965.     }
  966. }
  967.  
  968. function AFDate_KeystrokeEx(cFormat)
  969. {    /* This function validates the current keystroke event to make sure the
  970.     ** key pressed is reasonable for a date field. */
  971.     if(event.willCommit && !AFParseDateEx(AFMergeChange(event), cFormat)) {
  972.         /* Dates are only validated on commit */
  973.         if (event.willCommit) {
  974.             var cAlert = IDS_INVALID_DATE;
  975.             if (event.target != null)
  976.                 cAlert += " [ " + event.target.name + " ]";
  977.             app.alert(cAlert);
  978.             if (event.target != null)
  979.                 event.target.setFocus();
  980.         }
  981.         else
  982.             app.beep(0);
  983.         event.rc = false;
  984.     }
  985. }
  986.  
  987. function AFDate_Keystroke(pdf)
  988. {    /* OBSOLETE: Use AFDate_KeystrokeEx. */
  989.     var cOldFormats = new Array(
  990.         "m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
  991.         "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
  992.         "m/d/yy h:MM tt", "m/d/yy HH:MM" );
  993.  
  994.     AFDate_KeystrokeEx(cOldFormats[pdf]);
  995. }
  996.  
  997. function AFTime_Keystroke(ptf)
  998. {    /* This function validates the current keystroke event to make sure the
  999.     key pressed is reasonable for a time field. */
  1000.  
  1001.     if(event.willCommit && !AFParseTime(event.value, null))
  1002.                     /* times are only validated on commit */
  1003.     {
  1004.         if (event.willCommit) {
  1005.             var cAlert = IDS_INVALID_VALUE;
  1006.             if (event.target != null)
  1007.                 cAlert += " [ " + event.target.name + " ]";
  1008.             app.alert(cAlert);
  1009.         }
  1010.         else
  1011.             app.beep(0);
  1012.         event.rc = false;
  1013.     }
  1014. }
  1015.  
  1016. function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
  1017. {       /* This function formats a numeric value according to the parameters. */
  1018.  
  1019.     var value = AFMakeNumber(event.value);
  1020.     var sign = (value < 0 ? -1 : 1);
  1021.     var f = event.target;
  1022.  
  1023.     if(value == null)
  1024.     {
  1025.         event.value = "";
  1026.         return;
  1027.     }    
  1028.     if ((negStyle == 2 /* ParensBlack */ || negStyle == 3 /* ParensRed */) && value < 0)
  1029.         var formatStr = "(";
  1030.     else 
  1031.         var formatStr = "";
  1032.     
  1033.     if (bCurrencyPrepend)
  1034.         formatStr = formatStr + strCurrency;
  1035.         
  1036.     formatStr = formatStr + "%," + sepStyle + "." + nDec + "f";
  1037.     if (! bCurrencyPrepend)
  1038.         formatStr = formatStr + strCurrency;
  1039.         
  1040.     if ((negStyle == 2 /* ParensBlack */ || negStyle == 3 /* ParensRed */) && value < 0)
  1041.         formatStr = formatStr + ")";
  1042.  
  1043.     if (negStyle != 0 /* MinusBlack */ || bCurrencyPrepend)
  1044.         value = Math.abs(value);
  1045.         
  1046.     if (negStyle == 1 /* Red */ || negStyle == 3 /* ParensRed */) {
  1047.         if (sign > 0 )
  1048.             f.textColor = color.black;
  1049.         else 
  1050.             f.textColor = color.red;
  1051.     }
  1052.  
  1053.     var tmp = util.printf(formatStr, value);
  1054.     if (sign < 0 && bCurrencyPrepend && negStyle == 0)
  1055.         tmp = '-' + tmp; /* prepend the -ve sign */
  1056.     event.value = tmp;
  1057. }
  1058.  
  1059. function AFPercent_Format(nDec, sepStyle)
  1060. {       /* This function formats a percentage value according to the parameters. */
  1061.  
  1062.     var value = AFMakeNumber(event.value) * 100;
  1063.     
  1064.     var formatStr = "%," + sepStyle + "." + nDec + "f";
  1065.         
  1066.     if(value == null)
  1067.     {
  1068.         event.value = "";
  1069.         return;
  1070.     }    
  1071.  
  1072.     value = util.printf(formatStr, value);
  1073.     
  1074.     event.value = value + "%";
  1075. }
  1076.  
  1077. function AFSpecial_Format(psf)
  1078. {   /* This function formats a "special" value according to the "PropsSpecialFormat" parameter psf. */
  1079.     /* The special formats, indicated by psf, are: 0 = zip code, 1 = zip + 4, 2 = phone, 3 = SSN. */
  1080.     var value = event.value;
  1081.  
  1082.     if(!value) return;    
  1083.     switch (psf) {
  1084.     
  1085.         case 0:                         
  1086.             var formatStr = "99999";
  1087.             break;
  1088.         case 1:                         
  1089.             var formatStr = "99999-9999";
  1090.             break;
  1091.         case 2:                         /* must distinguish between 2 styles: with and without area code */
  1092.             var NumbersStr = util.printx("9999999999", value);      /* try to suck out 10 numeric chars */
  1093.             if (NumbersStr.length >= 10 )
  1094.                 var formatStr = "(999) 999-9999";
  1095.             else 
  1096.                 var formatStr = "999-9999";
  1097.             break;
  1098.         case 3:
  1099.             var formatStr = "999-99-9999";
  1100.             break;
  1101.     }
  1102.         
  1103.     event.value = util.printx(formatStr, value);
  1104. }
  1105.  
  1106. function AFParseDateYCount(cFormat)
  1107. {
  1108.     /* Determine the order of the date. */
  1109.     var yCount = 0;
  1110.     for (var i = 0; i < cFormat.length; i++) {
  1111.         switch (cFormat.charAt(i)) {
  1112.             case "\\":    /* Escape character. */
  1113.                 i++;
  1114.             break;
  1115.             case "y":
  1116.                 yCount += 1;
  1117.             break;
  1118.         }
  1119.     }
  1120.     return yCount;
  1121. }
  1122.  
  1123. function AFParseDateOrder(cFormat)
  1124. {
  1125.     /* Determine the order of the date. */
  1126.     var cOrder = "";
  1127.     for (var i = 0; i < cFormat.length; i++) {
  1128.         switch (cFormat.charAt(i)) {
  1129.             case "\\":    /* Escape character. */
  1130.                 i++;
  1131.             break;
  1132.             case "m":
  1133.                 if (cOrder.indexOf("m") == -1)
  1134.                     cOrder += "m";
  1135.             break;
  1136.             case "d":
  1137.                 if (cOrder.indexOf("d") == -1)
  1138.                     cOrder += "d";
  1139.             break;
  1140.             case "y":
  1141.                 if (cOrder.indexOf("y") == -1)
  1142.                     cOrder += "y";
  1143.             break;
  1144.         }
  1145.     }
  1146.  
  1147.     /* Make sure we have a full complement of 3 chars. */
  1148.     if (cOrder.indexOf("m") == -1)
  1149.         cOrder += "m";
  1150.     if (cOrder.indexOf("d") == -1)
  1151.         cOrder += "d";
  1152.     if (cOrder.indexOf("y") == -1)
  1153.         cOrder += "y";
  1154.  
  1155.     return cOrder;
  1156. }
  1157.  
  1158. function AFDate_FormatEx(cFormat)
  1159. {    /* cFormat is a format string with which the date is to be formatted. */
  1160.     if (!event.value) 
  1161.         return;    /* Blank fields remain blank */
  1162.  
  1163.     var date = AFParseDateEx(event.value, cFormat);
  1164.     if (!date) {
  1165.         event.value = "";
  1166.         return;
  1167.     }
  1168.     
  1169.     event.value = util.printd(cFormat, date);
  1170. }
  1171.  
  1172. function AFDate_Format(pdf)
  1173. {    /* OBSOLETE: Use AFDate_FormatEx. */
  1174.     var cOldFormats = new Array(
  1175.         "m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
  1176.         "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
  1177.         "m/d/yy h:MM tt", "m/d/yy HH:MM" );
  1178.  
  1179.     AFDate_FormatEx(cOldFormats[pdf]);
  1180. }
  1181.  
  1182. function AFTime_Format(ptf)
  1183. {    /* This function formats a time value according to the "PropsTimeFormat" parameter ptf.
  1184.     ** The time formats, indicated by ptf, are:
  1185.     ** ptf             format                                                          
  1186.     ** ---             ------                                                          
  1187.     ** 0               PTF_24HR_MM     [ 14:30      ]
  1188.     ** 1               PTF_12HR_MM     [ 2:30 PM    ]
  1189.     ** 2               PTF_24HR_MM_SS  [ 14:30:15   ]
  1190.     ** 3               PTF_12HR_MM_SS  [ 2:30:15 PM ] */
  1191.  
  1192.     if(!event.value) return;    /* Blank fields remain blank */
  1193.  
  1194.     var date = new AFParseTime(event.value, null);
  1195.     if(!date) {
  1196.         event.value = "";
  1197.         return;
  1198.     }
  1199.  
  1200.     var cFormats = new Array(
  1201.         "HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt" ); 
  1202.     
  1203.     event.value = util.printd(cFormats[ptf], date);
  1204. }
  1205.  
  1206. function AFSignatureLock(doc, cOperation, cFields, bLock)
  1207. {    // Locks or unlocks a set of fields according to the specified operation.
  1208.     /* Field name separator is one or more spaces followed by a comma, 
  1209.     ** followed by one or more spaces.
  1210.     ** or an array of field names */
  1211.      var aFields = AFMakeArrayFromList(cFields);
  1212.  
  1213.     /* Three cases: ALL, EXCEPT, THESE for the field name list. */
  1214.     if (cOperation != "THESE") {
  1215.         for (var i = 0; i < doc.numFields; i++) {
  1216.             var f = doc.getField(doc.getNthFieldName(i));
  1217.                 
  1218.             f.readonly = bLock;
  1219.          }
  1220.     }
  1221.     
  1222.     if (cOperation == "EXCEPT")
  1223.         /* EXCEPT = ALL(lock) then THESE(unlock) */
  1224.         bLock = !bLock;
  1225.  
  1226.     if (cOperation == "THESE" || (cOperation == "EXCEPT" && !bLock)) {
  1227.         for (var i = 0; i < aFields.length; i++) {
  1228.             var f = doc.getField(aFields[i]);
  1229.             var a = f.getArray();
  1230.  
  1231.             for (var j = 0; j < a.length; j++) {
  1232.                 a[j].readonly = bLock;
  1233.             }
  1234.         }
  1235.     }
  1236. }
  1237.  
  1238. function AFSignature_Format(cOperation, cFields)
  1239. {    /* This function is invoked at format time but really is used to lock fields
  1240.     ** in the document. We unlock all the specified fields if the value is
  1241.     ** null (which means the signature hasn't been applied). */
  1242.  
  1243.     var bLock = (event.value != "");
  1244.  
  1245.     AFSignatureLock(this, cOperation, cFields, bLock);
  1246. }
  1247.